home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-68k-src / machines / amiga68k / libsrc / _main.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  89 lines

  1. /*  _main()-Routine fuer vbcc-Amiga-Version  */
  2. /*  initialisiert stdin, stdout, stderr etc. */
  3. /* 05-Oct-98 phx _ctors/_dtors support       */
  4. /* 06-Feb-99 phx _ctors/_dtors support for   */
  5. /*               vlink 0.6c (1st word is -1) */
  6.  
  7. /*  MATH_IEEE definieren, wenn die MathIeee-Libraries benutzt werden sollen */
  8.  
  9. #include <stddef.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <libraries/dos.h>
  13. #include <proto/dos.h>
  14.  
  15. FILE *stdin,*stdout,*stderr,*_firstfile=0,*_lastfile=0;
  16.  
  17. extern int main(int, char **);
  18. extern BPTR _stdin,_stdout,_stderr;
  19. extern __far void (*_ctors[])(),(*_dtors[])();
  20.  
  21. #ifdef MATH_IEEE
  22. #include <proto/exec.h>
  23. struct Library *MathIeeeDoubBasBase,*MathIeeeDoubTransBase,*MathIeeeSingBasBase;
  24. #endif
  25.  
  26. void _main(int argc, char **argv)
  27. {
  28.     void (**ctors)() = _ctors;
  29.  
  30.     stdin=(FILE *)malloc(sizeof(FILE));
  31.     stdout=(FILE *)malloc(sizeof(FILE));
  32.     stderr=(FILE *)malloc(sizeof(FILE));
  33.     if(!stdin||!stdout||!stderr) exit(EXIT_FAILURE);
  34.     stdin->filehandle=(char*)_stdin;
  35.     stdin->flags=_READABLE;if(IsInteractive(_stdin)) stdin->flags|=_UNBUF;
  36.     stdout->filehandle=(char*)_stdout;
  37.     stdout->flags=_WRITEABLE;if(IsInteractive(_stdout)) stdout->flags|=_LINEBUF;
  38.     stderr->filehandle=(char*)_stderr;
  39.     stderr->flags=_WRITEABLE;if(IsInteractive(_stderr)) stderr->flags|=_UNBUF;
  40.     stdin->pointer=stdout->pointer=stderr->pointer=0;
  41.     stdin->base=stdout->base=stderr->base=0;
  42.     stdin->count=stdout->count=stderr->count=0;
  43.     stdin->bufsize=stdout->bufsize=stderr->bufsize=0;
  44.     stdin->prev=0;stdin->next=stdout;
  45.     stdout->prev=stdin;stdout->next=stderr;
  46.     stderr->prev=stdout;stderr->next=0;
  47.     _firstfile=stdin;_lastfile=stderr;
  48. #ifdef MATH_IEEE
  49.     if(!(MathIeeeSingBasBase=OpenLibrary("mathieeesingbas.library",37L)))
  50.         exit(EXIT_FAILURE);
  51.     if(!(MathIeeeDoubBasBase=OpenLibrary("mathieeedoubbas.library",37L)))
  52.         exit(EXIT_FAILURE);
  53.     if(!(MathIeeeDoubTransBase=OpenLibrary("mathieeedoubtrans.library",37L)))
  54.         exit(EXIT_FAILURE);
  55. #endif
  56.     if(ctors++) while(*ctors) (*ctors++)();  /* call constructors */
  57.     exit(main(argc,argv));
  58. }
  59.  
  60. /*  Wie sieht das genau aus? Das ist eine Asm-Routine   */
  61. extern void _exit();
  62.  
  63. struct __exitfuncs *__firstexit;
  64.  
  65. /*  exit()-Routine fuer vbcc-Amiga-Version  */
  66. void exit(int returncode)
  67. {
  68.     void (**dtors)() = _dtors;
  69.     int i;
  70.  
  71.     struct __exitfuncs *p=__firstexit;
  72.     /*  atexit-Routinen starten */
  73.     while(p){p->func();p=p->next;}
  74.     if (dtors) {
  75.         for (i=1; *dtors[i]; i++);
  76.         while (--i) (*dtors[i])();  /* call destructors */
  77.     }
  78. #ifdef MATH_IEEE
  79.     if(MathIeeeDoubTransBase) CloseLibrary(MathIeeeDoubTransBase);
  80.     if(MathIeeeDoubBasBase) CloseLibrary(MathIeeeDoubBasBase);
  81.     if(MathIeeeSingBasBase) CloseLibrary(MathIeeeSingBasBase);
  82. #endif
  83.     /*  alle offenen Files schliessen   */
  84.     while(_firstfile&&!fclose(_firstfile));
  85.     /*  allen Speicher freigeben        */
  86.     _freemem();
  87.     _exit(returncode);
  88. }
  89.